--[[
    杰克高手玩家游戏实体
]]--

local blaze = require "blaze"
local game = require "club.threecard.jacksorbetter"

local GameObject = require "entities.interfaces.GameObject"
local Client = require "entities.interfaces.Client"
local Player = require "entities.interfaces.Player"

local log = blaze.logging.get("JobPlayer")

local M = game.kbe.entity("JobPlayer", GameObject, Client, Player)

function M:__init__()
    GameObject.__init__(self)
    Client.__init__(self)
    Player.__init__(self)
end

--[[ =============================
             服务端接口
================================== ]]--

function M:bet(amount)
    self:cellCall("bet", amount)
end

function M:hold(card_ids)
    self:cellCall("hold", card_ids)
end

function M:double()
    self:cellCall("double_it", 0)
end

function M:pick(index)
    self:cellCall("pick", index)
end

--[[ =============================
             属性变更回调
================================== ]]--

function M:set_current_win(old)
    if self:is_me() then
        log.debug(string.format("即将赢取：%s", self.current_win))
        game.store.ingame.set_current_win({old = old, current = self.current_win})
    end
end

function M:set_phase(old)
    if self:is_me() then
        log.debug(string.format("当前阶段：%s", self.phase))
        game.store.ingame.set_phase({old = old, phase = self.phase})
    end
end

--[[ =============================
             服务端回调
================================== ]]--

function M:on_reveal(card_ids, rank_class)
    log.debug(string.format("on_reveal:%s rank_class:%s", blaze.dump(card_ids), rank_class))
    game.store.ingame.on_reveal({card_ids = card_ids, rank_class = rank_class})
end

function M:on_settle(result, allow_double)
    log.debug(string.format("on_settle:result=%s allow_double=%s", result, allow_double))
    game.store.ingame.on_settle({result = result, allow_double = allow_double});
end

return M